package com.crm.system.controller.couponManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.couponManager.CouponQO;
import com.crm.model.vo.couponManager.CouponVO;
import com.crm.system.service.couponManager.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:chaifuyou
 * @Date: 2021/5/11 15:52
 */
@RequestMapping("/coupon")
@RestController
public class CouponController {

    @Autowired
    private CouponService couponService;

    /**
     * 优惠券列表
     * @return
     */
    @PostMapping("/couponPageList")
    public DataResponse selectFollowPlanList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                             @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                             CouponQO couponQO//查询条件
    ){
        DhPageInfo<CouponVO> page = couponService.selectFollowPlanList(couponQO,pageIndex,pageSize,sortName,sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),page);
    }

    /**
     * 新增/修改优惠券
     * @return
     */
    @PostMapping("/addCouponOrUpdateCoupon")
    public DataResponse addCouponOrUpdateCoupon(@RequestBody CouponQO couponQO){
        boolean b = couponService.addCouponOrUpdateCoupon(couponQO);
        if (b){
            return new DhResponse(ResponseCodeEnum.COUPON_NAME_EX.getResponseCode());
        }
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 新建合同-查询可领取的优惠券列表
     * @return
     */
    @PostMapping("/selectAvailableCouponPageList")
    public DataResponse selectAvailableCouponPageList(@RequestBody CouponQO couponQO//查询条件
                                                      ){
        DhPageInfo<CouponVO> page = couponService.selectAvailableCouponPageList(couponQO,couponQO.getPageIndex(),couponQO.getPageSize());
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),page);
    }

    /**
     * 可领取的优惠券列表
     * @return
     */
    @PostMapping("/availableCouponList")
    public DataResponse availableCouponList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             CouponQO couponQO//查询条件
    ){
        DhPageInfo<CouponVO> page = couponService.availableCouponList(couponQO,pageIndex,pageSize);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),page);
    }

    /**
     * 优惠券详情
     * @param couponId
     * @param customerId 客户id，客户详情页面进入才传值
     * @return
     */
    @GetMapping("/couponInfo")
    public DataResponse couponInfo(String couponId,String customerId){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),couponService.couponInfo(couponId,customerId));
    }
}
